import javax.swing.JOptionPane;
public class GuessNumber {
    public static void main(String args[]){
        int rightNumber=0;
        int guessNumber;
        String guessString;
        String continueString;
        boolean guessWrong=true;
        String message="";
        while(true){
            rightNumber=(int)(Math.random()*(100));
            guessString=JOptionPane.showInputDialog("请输入你要猜的数(1-100之间)：");
            guessNumber=Integer.parseInt(guessString);
            do{
                if(guessNumber==rightNumber){
                    JOptionPane.showMessageDialog(null,message+"你猜对了！数字为："+rightNumber);
                    guessWrong=false;
                    break;
                }else if(guessNumber>rightNumber){
                    message+="你猜的数"+guessNumber+"太大了！\n";
                    guessString=JOptionPane.showInputDialog(message+"再猜！");
                }else {
                    message+="你猜的数"+guessNumber+"太小了！\n";
                    guessString=JOptionPane.showInputDialog(message+"再猜！");
                }
                guessNumber=Integer.parseInt(guessString);
            }while(guessWrong);
            continueString=JOptionPane.showInputDialog("是否继续？Y/N");
            if(!continueString.equals("Y"))break;
        }
    }
}